/*
 * Copyright (C) 2013 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.jakewu.horizontalgridview.utils;

import android.app.ActivityManager;
import android.content.Context;
import android.net.Uri;
import android.util.Log;

import com.jakewu.horizontalgridview.MainActivity;
import com.squareup.picasso.Picasso;


public class Utils {


    private static Context CardContext = null;

    public static Context getCardContext() {
        return CardContext;
    }

    public static void setCardContext(Context context) {
        CardContext = context;
    }

    public static Picasso getPicassoInstance() {
        Picasso picasso = null;
        if (null != CardContext) {
            picasso = ((MainActivity) CardContext).getPicassoInstance();
        }
        return picasso;
    }


    public static int calculateMemoryCacheSize(Context context) {
        ActivityManager am = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
        int memoryClass = am.getMemoryClass();
        Log.v("Utils", "Memory Size:" + memoryClass);
        return 1024 * 1024 * memoryClass / 25;
    }

    public static boolean isWebUri(Uri uri) {
        String s;
        if (uri.getScheme() == null) {
            s = null;
        } else {
            s = uri.getScheme().toLowerCase();
        }
        return "http".equals(s) || "https".equals(s);
    }

}
